//
//  KFDNotificationViewController.m
//  KFD
//
//  Created by JIRENTIANXIANG on 7/4/15.
//  Copyright © 2015 kfd. All rights reserved.
//

#import "KFDMessageNotificationSettingsViewController.h"
#import "KFDUIConfigurator.h"
#import "KFDSettingsManager.h"

@interface KFDMessageNotificationSettingsViewController ()

@property (weak, nonatomic) IBOutlet UISwitch *masterSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *soundSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *vibrationSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *contentSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *flashSwitch;

@end

@implementation KFDMessageNotificationSettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    KFDUIConfigurator* uiConfigurator=[KFDUIConfigurator configuratorForViewController:self];
    [uiConfigurator configureNavigationBarWithBackAction:@selector(goBack)];
    self.title=@"消息通知";
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    KFDSettingsManager* manager=[KFDSettingsManager sharedManager];
    [manager loadMessageNotificationSettings];
    [self.masterSwitch setOn:manager.messageNotificationSettings.masterSwitch];
    [self.soundSwitch setOn:manager.messageNotificationSettings.sound];
    [self.vibrationSwitch setOn:manager.messageNotificationSettings.vibration];
    [self.contentSwitch setOn:manager.messageNotificationSettings.content];
    [self.flashSwitch setOn:manager.messageNotificationSettings.flash];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    KFDSettingsManager* manager=[KFDSettingsManager sharedManager];
    manager.messageNotificationSettings.masterSwitch=self.masterSwitch.isOn;
    manager.messageNotificationSettings.sound=self.soundSwitch.isOn;
    manager.messageNotificationSettings.vibration=self.vibrationSwitch.isOn;
    manager.messageNotificationSettings.content=self.contentSwitch.isOn;
    manager.messageNotificationSettings.flash=self.flashSwitch.isOn;
    [manager saveMessageNotificationSettings];
}

-(void)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)switchChanged:(UISwitch*)sender {
    if (sender==self.masterSwitch&&!sender.isOn) {
        [self.soundSwitch setOn:NO];
        [self.vibrationSwitch setOn:NO];
        [self.contentSwitch setOn:NO];
        [self.flashSwitch setOn:NO];
    }else if(sender.isOn){
        [self.masterSwitch setOn:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
